<%@page import="models.Customer"%>
<%@page import="utils.UsersInfo"%>
<%@page import="models.SolutionSubscription"%>
<%@ page import="models.Benefit" %>
<%@ page import="models.Location" %>
<%@ page import="models.Area" %>
<%@ page import="java.util.List, java.util.HashMap" %>
<%@ page import = "java.util.Date" %>
<%@ page import="com.google.appengine.api.blobstore.BlobInfo, com.google.appengine.api.blobstore.BlobInfoFactory, com.google.appengine.api.blobstore.BlobKey" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService, com.google.appengine.api.blobstore.BlobstoreServiceFactory, com.google.appengine.api.datastore.DatastoreServiceFactory" %>  

<%@ page import="com.googlecode.objectify.Objectify, com.googlecode.objectify.ObjectifyService, com.googlecode.objectify.Query" %>


<!-- content -->
<!--<a id="mainContent" name="mainContent"/>-->
<div id="lotusContent">
<div class="lotusLayout lotusHeader">
<!--<h1>Savvy Solutions</h1>
<div class="lotusDetails">The Global Operations Excellence collection of Savvy Solutions resulting in cost savings for the company</div>-->
</div>
<!-- View selector -->
<div class="lotusActionBar lotusBtnContainer">
<!-- Buttons -->
<!--<span class="lotusBtn lotusBtnAction lotusLeft">
<a href="/blogs/roller-ui/myblogs/newentry">New Entry</a>
</span>-->
</div>
<br>
 <center>
<!-- <table width="100%" style="background-color:#FDB813" cellpadding="10">
<tr><td></td></tr>
<tr>
<td>
<table cellpadding="20">
<tr><td bgcolor="#CA8F02" width="10%"><a href="javascript:CustomersInfo()" style="text-decoration:none"><font style="color:white;font-weight:bold;font-size:15px;font-family:verdana">Customers</a></td>
<td bgcolor="#CA8F02" width="15%"><a href="javascript:ProcessInfo()" style="text-decoration:none"><font style="color:white;font-weight:bold;font-size:15px;font-family:verdana">Process Area</td>
<td bgcolor="#CA8F02" width="10%"><a href="javascript:BenefitsInfo()" style="text-decoration:none"><font style="color:white;font-weight:bold;font-size:15px;font-family:verdana">Benefits</td>
<td bgcolor="#CA8F02" width="10%"><a href="javascript:SitesInfo()" style="text-decoration:none"><font style="color:white;font-weight:bold;font-size:15px;font-family:verdana">Locations</td>
</table>
</td>
</tr>
</table> -->
</center>
<br><br>
<div id="dynamicdisplay">

<%


String userEmailID = (String) pageContext.getAttribute("USER_EMAILID", PageContext.PAGE_SCOPE); 


String KeyTemp = request.getParameter("Key");
String CatTemp = request.getParameter("Cat");

String  htmlstr = "", tempstr = "";
int counter = 1, row = 2;
boolean subscribed = false;

if ( KeyTemp == null || KeyTemp.equals("") ){
	KeyTemp = "CustomersInfo";
}

if (KeyTemp.equalsIgnoreCase("CustomersInfo")) {
	htmlstr = "<div class='lotusTabContainer'  ><ul class='lotusTabs'><li class ='lotusSelected'><a  href='javascript:CustomersInfo()'>Customers</a></li><li ><a href='javascript:ProcessInfo()' >Process Area</a></li><li><a  href='javascript:BenefitsInfo()'>Benefits</a></li><li ><a href='javascript:SitesInfo()'>Locations</a></li></ul></div>";
	htmlstr	=	htmlstr+ "<table>";

	Objectify ofy = ObjectifyService.begin();
	Query<Customer> q = ofy.query(Customer.class).order("custIndex");
	for ( Customer f : q.fetch() ) {
		Query<SolutionSubscription> qq = ofy.query(SolutionSubscription.class).filter("custID", f.getCustID()).filter("subscribeBY", userEmailID);
		subscribed = false;
		for ( SolutionSubscription ff : qq.fetch() ) {
			subscribed = true;
			break;
		}
		if ( row == 2) {
			htmlstr	=	htmlstr +	"<TR>";
		}
		
		if (subscribed)
		{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getCustIndex()+ "\" onclick=\"UnSubscribeDocValue('" + f.getCustID() + "','" + f.getCustIndex() + "')\" type=checkbox name=chk><FONT style='FONT-WEIGHT: bold' color=#fdb813>Subscribed </FONT>" + f.getCustName() + "</TD>";
		}else{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getCustIndex()+ "\" onclick=\"StoreDocValue('" + f.getCustID() + "','" + f.getCustIndex() + "')\" type=checkbox name=chk>" + f.getCustName() + "</TD>";
		}
		
		row++;
		
		if ( row == 4){
			htmlstr	=	htmlstr +	"</TR>";
			row = 0;
		}
		
	}
	
}else if (KeyTemp.equalsIgnoreCase("ProcessInfo")) {
	htmlstr = "<div class='lotusTabContainer'  ><ul class='lotusTabs'><li><a  href='javascript:CustomersInfo()'>Customers</a></li><li class ='lotusSelected' ><a href='javascript:ProcessInfo()' >Process Area</a></li><li><a  href='javascript:BenefitsInfo()'>Benefits</a></li><li ><a href='javascript:SitesInfo()'>Locations</a></li></ul></div>";		
	htmlstr	=	htmlstr + "<table>";

	Objectify ofy = ObjectifyService.begin();
	Query<Area> q = ofy.query(Area.class).order("areaIndex");
	for ( Area f : q.fetch() ) {
		Query<SolutionSubscription> qq = ofy.query(SolutionSubscription.class).filter("areaID", f.getAreaID()).filter("subscribeBY", userEmailID);
		subscribed = false;
		for ( SolutionSubscription ff : qq.fetch() ) {
			subscribed = true;
			break;
		}
		if ( row == 2) {
			htmlstr	=	htmlstr +	"<TR>";
		}

		if (subscribed)
		{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getAreaIndex() +"\" onclick=\"UnSubscribeDocValue('" + f.getAreaID() + "','" + f.getAreaIndex() + "')\" type=checkbox name=chk><FONT style='FONT-WEIGHT: bold' color=#fdb813>Subscribed </FONT>" + f.getAreaName() + "</TD>";
		}else{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getAreaIndex() +"\" onclick=\"StoreDocValue('" + f.getAreaID() + "','" + f.getAreaIndex() + "')\" type=checkbox name=chk>" + f.getAreaName() + "</TD>";
		}
		
		row++;
		
		if ( row == 4){
			htmlstr	=	htmlstr +	"</TR>";
			row = 0;
		}

	}
	
}else if (KeyTemp.equalsIgnoreCase("BenefitsInfo")) {
	boolean firstTime = true;
	String lastBenefitType = "";
	
	htmlstr = 	"<div class='lotusTabContainer'  ><ul class='lotusTabs'><li><a  href='javascript:CustomersInfo()'>Customers</a></li><li><a href='javascript:ProcessInfo()' >Process Area</a></li><li class ='lotusSelected'><a  href='javascript:BenefitsInfo()'>Benefits</a></li><li ><a href='javascript:SitesInfo()'>Locations</a></li></ul></div>";		
	
	

	htmlstr	=	htmlstr	+	"<table>";
	Objectify ofy = ObjectifyService.begin();
	//Query<Benefit> q = ofy.query(Benefit.class).order("benefitIndex").order("benefitType");
	Query<Benefit> q = ofy.query(Benefit.class).order("benefitIndex");
	//q.order("benefitType");
	for ( Benefit f : q.fetch() ) {
		
		if (firstTime){
			lastBenefitType = (String) f.getBenefitType();
			firstTime = false;
			htmlstr	=	htmlstr +	"<TR>";
			htmlstr	=	htmlstr	+ 	"<td><br><b><font style='font-weight:bold;font-size:13px;font-family:Arial'>" + f.getBenefitType() + "<br></td>";
			htmlstr	=	htmlstr +	"</TR>";

		}
		
		Query<SolutionSubscription> qq = ofy.query(SolutionSubscription.class).filter("benefitID", f.getBenefitID()).filter("subscribeBY", userEmailID);
		subscribed = false;
		for ( SolutionSubscription ff : qq.fetch() ) {
			subscribed = true;
			break;
		}
		
		if ( !f.getBenefitType().equalsIgnoreCase(lastBenefitType) ){
			htmlstr	=	htmlstr +	"<TR>";
			htmlstr	=	htmlstr	+ 	"<td><br><b><font style='font-weight:bold;font-size:13px;font-family:Arial'>" + f.getBenefitType() + "<br></td>";
			htmlstr	=	htmlstr +	"</TR>";
			lastBenefitType = f.getBenefitType();
		}
		
		if ( row == 2) {
			htmlstr	=	htmlstr +	"<TR>";
		}

		if (subscribed)
		{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getBenefitIndex() +"\" onclick=\"UnSubscribeDocValue('" + f.getBenefitID() + "','" + f.getBenefitIndex() + "')\" type=checkbox name=chk><FONT style='FONT-WEIGHT: bold' color=#fdb813>Subscribed </FONT>" + f.getBenefitName() + "</TD>";
		}else{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chk"+ f.getBenefitIndex() +"\" onclick=\"StoreDocValue('" + f.getBenefitID() + "','" + f.getBenefitIndex() + "')\" type=checkbox name=chk>" + f.getBenefitName() + "</TD>";
		}
		
		row++;
		
		if ( row == 4){
			htmlstr	=	htmlstr +	"</TR>";
			row = 0;
		}

	}			
}else if (KeyTemp.equalsIgnoreCase("SitesInfo")) {
	boolean firstTime = true;
	String lastRegionName = "";
	
	htmlstr = 	"<div class='lotusTabContainer'  ><ul class='lotusTabs'><li><a  href='javascript:CustomersInfo()'>Customers</a></li><li><a href='javascript:ProcessInfo()' >Process Area</a></li><li><a  href='javascript:BenefitsInfo()'>Benefits</a></li><li class ='lotusSelected'><a href='javascript:SitesInfo()'>Locations</a></li></ul></div>";		
	
	

	htmlstr	=	htmlstr	+	"<table>";
	Objectify ofy = ObjectifyService.begin();
	Query<Location> q = ofy.query(Location.class).order("LocationRegionID");
	for ( Location f : q.fetch() ) {
		
		if (firstTime){
			lastRegionName = (String) f.getLocationRegionName();
			firstTime = false;
			htmlstr	=	htmlstr +	"<TR>";
			htmlstr	=	htmlstr	+ 	"<td><br><b><font style='font-weight:bold;font-size:13px;font-family:Arial'>" + f.getLocationRegionName() + "<br></td>";
			htmlstr	=	htmlstr +	"</TR>";					
		}
		
		Query<SolutionSubscription> qq = ofy.query(SolutionSubscription.class).filter("locID", f.getLocID()).filter("subscribeBY", userEmailID);
		subscribed = false;
		for ( SolutionSubscription ff : qq.fetch() ) {
			subscribed = true;
			break;
		}
		
		if ( !f.getLocationRegionName().equalsIgnoreCase(lastRegionName) ){
			htmlstr	=	htmlstr +	"<TR>";
			htmlstr	=	htmlstr	+ 	"<td><br><b><font style='font-weight:bold;font-size:13px;font-family:Arial'>" + f.getLocationRegionName() + "<br></td>";
			htmlstr	=	htmlstr +	"</TR>";
			lastRegionName = f.getLocationRegionName();
		}
		
		if ( row == 2) {
			htmlstr	=	htmlstr +	"<TR>";
		}

		if (subscribed)
		{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chkLocations"+ f.getLocationIndex() +"\" onclick=\"UnSubscribeLocDocValue('" + f.getLocID() + "','" + f.getLocationIndex() + "')\" type=checkbox name=chk><FONT style='FONT-WEIGHT: bold' color=#fdb813>Subscribed </FONT>" + f.getLocationName() + "</TD>";
		}else{
			htmlstr	=	htmlstr +	"<TD><INPUT id=\"chkLocations"+ f.getLocationIndex() +"\" onclick=\"StoreValue('" + f.getLocID() + "','" + f.getLocationIndex() + "')\" type=checkbox name=chk>" + f.getLocationName() + "</TD>";
		}
		
		row++;
		
		if ( row == 4){
			htmlstr	=	htmlstr +	"</TR>";
			row = 0;
		}

	}			
	
}

htmlstr	=	htmlstr	+	"</table><br><br>";


%>

<%=htmlstr%>


</div>

<input type='button' class='lotusBtn lotusBtnAction lotusLeft' value = 'Subscribe' onclick='javascript:savedoc()'><input type='button' class='lotusBtn lotusBtnAction lotusLeft' value='UnSubscribe' onclick='javascript:Unsavedoc()'><input type='button' class='lotusBtn lotusBtnAction lotusLeft' value='Cancel' onclick='javascript:canceldoc()'>

<br></div>


<!--End of Lotus Content-->
</div>
<!--End of Lotus Main-->
</div>
<!-- Footer gets moved to within Frame div in weblog.vm so closing tags need to go in weblog.vm - MTodd November 1 2007 </body> </html> -->
</div>
</div>


<input name="KeyVal" type="hidden" value="">
<input name="UnscribeKeyVal" type="hidden" value="">
<input name="txtCategory" type="hidden" value="<%=KeyTemp%>">
<input name="KeyValBenefits" type="hidden" value="">
<input name="SaveOptions" type="hidden" value="0">
<input name="HTTP_Cookie" type="hidden" value="redirectto=/global/collaboration/SavvySol.nsf/frmsavvy%3FOpenForm%26login; LtpaToken=ZDKFFoPfuAGbPyVskMUDPgxWENdj6diTwzdqpeE75D7FBQstuBp54YMspDnQC9QK954X+DXijT/vWRAgUVFNx1YH5mHGt4jPCB0tifWosuGt2pgJbNa7IjiTKFONwPS/0a8uLCYmTmXAa3McMVWDrzC94QuiFJQFf2bJLqwT49kSa2czaPaL8+wPbTixFYVafkQicymLpty9Wg/82xzU4Ngnvk4yDky8FYgPnMPudwRgJMlD+7iu0JajQHyKgSlbe9VD5EwdP0vgocohqPS82xDEZeyv/GMv9nLoQglzfPOhPtAibxTgaxIqOoD/S0F0zShSxZAsawd38k99RwSuhuc2PO/nj4HCukoOIqhiwSNOwLVwWtrZEw==">
<input name="Query_String_Decoded" type="hidden" value="OpenForm&amp;login">
<input name="Remote_User" type="hidden" value="CN=Siriwut Youdee/OU=TH/OU=Asia/O=Celestica">
<input name="Query_String" type="hidden" value="OpenForm&amp;login">
<input name="dbName" type="hidden" value="global/collaboration/SavvySol.nsf">
<input name="Position" type="hidden" value="">
<input name="curUsername" type="hidden" value="CN=Siriwut Youdee/OU=TH/OU=Asia/O=Celestica">
<input name="QuickSearch" type="hidden" value="0">
<input name="UserProfileInfo" type="hidden" value="">
<input name="txtProfileUNID" type="hidden" value="">


